package presale_house.service.impl;

import presale_house.entity.AdminDo;
import presale_house.service.AdminService;
import presale_house.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class AdminServiceImpl implements AdminService {
    @Override
    public boolean validateAdmin(AdminDo adminDo) {
        String userName= adminDo.getUserName();
        String pwdParam=adminDo.getPwd();
        String sql="select  pwd from  manager where user_name = ?";
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet resultSet=null;
        try {
            conn = DBUtil.getConn();
            if (conn == null) {
                return false;
            }
            ps=conn.prepareStatement(sql);
            ps.setString(1,userName);
             resultSet=ps.executeQuery();
            while(resultSet.next()){
                String pwd=resultSet.getString(1);
                if(pwdParam.equals(pwd)){
                    return true;
                }
            }

        }catch(Exception e) {
            throw new RuntimeException(e);
        } finally {//关闭资源
            DBUtil.closeRs(resultSet);
            DBUtil.closePs(ps);
            DBUtil.closeConn(conn);
        }
        return false;
    }
}
